package cn.iocoder.yudao.module.reading.controller.app.recording.vo;

import cn.iocoder.yudao.module.reading.framework.vo.BaseUrlConvertVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 配音记录 Response VO
 *
 * @author 芋道源码
 */
@Schema(description = "用户 APP - 配音记录 Response VO")
@Data
@EqualsAndHashCode(callSuper = false)
public class RecordingRespVO extends BaseUrlConvertVO {

    @Schema(description = "配音记录ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long id;

    @Schema(description = "绘本ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long bookId;

    @Schema(description = "绘本页面ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long pageId;

    @Schema(description = "配音文件URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://example.com/recording.mp3")
    private String audioUrl;

    @Schema(description = "配音时长（秒）", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
    private Integer duration;

    @Schema(description = "系统评分（0-100）", example = "85")
    private Integer score;

    @Schema(description = "是否可分享", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
    private Boolean isShareable;

    @Schema(description = "录音质量", example = "medium")
    private String recordingQuality;

    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-01-06T10:30:00")
    private LocalDateTime createTime;

    @Schema(description = "绘本信息")
    private BookInfoVO bookInfo;

    @Schema(description = "页面信息")
    private PageInfoVO pageInfo;

    @Schema(description = "绘本信息")
    @Data
    public static class BookInfoVO {
        @Schema(description = "绘本标题", example = "The Magic Key")
        private String title;

        @Schema(description = "绘本封面", example = "https://example.com/book-cover.jpg")
        private String cover;

        @Schema(description = "绘本集标题", example = "牛津树1级")
        private String bookSetTitle;
    }

    @Schema(description = "页面信息")
    @Data
    public static class PageInfoVO {
        @Schema(description = "页码", example = "1")
        private Integer pageNumber;

        @Schema(description = "页面图片URL", example = "https://example.com/page1.jpg")
        private String imageUrl;

        @Schema(description = "文字内容", example = "Once upon a time...")
        private String textContent;
    }

    /**
     * 转换URL字段
     * 将相对路径转换为完整URL
     */
    @Override
    public void convertUrls() {
        this.audioUrl = convertUrl(this.audioUrl);

        // 转换嵌套对象中的URL
        if (this.bookInfo != null) {
            this.bookInfo.cover = convertUrl(this.bookInfo.cover);
        }
        if (this.pageInfo != null) {
            this.pageInfo.imageUrl = convertUrl(this.pageInfo.imageUrl);
        }
    }
}
